package com.example.vv.frameWork.view;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class ChatDetailItemDecoration extends RecyclerView.ItemDecoration {
    private int space;
    private int top;
    private int top2=0;


    public ChatDetailItemDecoration(int space, int top) {
        this.space = space;
        this.top = top;
    }

    public ChatDetailItemDecoration(int space, int top1, int top2) {
        this.space = space;
        this.top = top1;
        this.top2 = top2;
    }


    @Override
    public void getItemOffsets( Rect outRect,  View view, RecyclerView parent, RecyclerView.State state) {
        int childAdapterPosition = parent.getChildAdapterPosition(view);
        RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
        if(layoutManager instanceof GridLayoutManager){
            GridLayoutManager gridLayoutManager= (GridLayoutManager) layoutManager;
            int spanCount = gridLayoutManager.getSpanCount();
           if(childAdapterPosition==0||spanCount%childAdapterPosition==0){
               //第一个
               outRect.set(space,top,space/2,0);
           }else if(spanCount%(childAdapterPosition+1)==0){
               //最后一个
               outRect.set(space/2,top,space,0);
           }else{
               //中间
               outRect.set(space/2,top,space/2,0);
           }

        }
        /*if(top2!=0){
            if(childAdapterPosition>=2){
                //第二行
                if(childAdapterPosition%2==0){
                    //左边
                    outRect.left=space;
                    outRect.right=space/2;
                    outRect.set(space,top2,space/2,0);
                }else{
                    //右边
            *//*outRect.left=space/2;
            outRect.right=space;*//*
                    outRect.set(space/2,top2,space,0);
                }
            }else{
                if(childAdapterPosition%2==0){
                    //左边
                    outRect.left=space;
                    outRect.right=space/2;
                    outRect.set(space,top,space/2,0);
                }else{
                    //右边
            *//*outRect.left=space/2;
            outRect.right=space;*//*
                    outRect.set(space/2,top,space,0);
                }
            }
        }else{
            if(childAdapterPosition%2==0){
                //左边
                outRect.left=space;
                outRect.right=space/2;
                outRect.set(space,top,space/2,0);
            }else{
                //右边
            *//*outRect.left=space/2;
            outRect.right=space;*//*
                outRect.set(space/2,top,space,0);
            }
        }*/





    }


}
